| Conditions | 1 |
| Paths | 1 |
| Total Lines | 202 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* jshint -W101, -W098 */ |
||
| 90 | describe('data api', function() { |
||
| 91 | it('test address', function(cb) { |
||
| 92 | client.address("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", function(err, address) { |
||
| 93 | assert.ifError(err); |
||
| 94 | assert.ok(address['address']); |
||
| 95 | assert.equal(address['address'], '3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief'); |
||
| 96 | |||
| 97 | // trim off deprecated fields |
||
| 98 | delete address.category; |
||
| 99 | delete address.tag; |
||
| 100 | delete address.first_seen; |
||
| 101 | delete address.last_seen; |
||
| 102 | delete address.total_transactions_in; |
||
| 103 | delete address.total_transactions_out; |
||
| 104 | delete address.unconfirmed_utxos; |
||
| 105 | // trim off new fields |
||
| 106 | delete address.first_tx; |
||
| 107 | delete address.last_tx; |
||
| 108 | |||
| 109 | assert.deepEqual( |
||
| 110 | address, |
||
| 111 | require('./test_data/address.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief') |
||
| 112 | ); |
||
| 113 | |||
| 114 | cb(); |
||
| 115 | }); |
||
| 116 | }); |
||
| 117 | it('test addressTransactions', function(cb) { |
||
| 118 | client.addressTransactions("3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief", {limit: 20}, function(err, address_txs) { |
||
| 119 | assert.ifError(err); |
||
| 120 | |||
| 121 | assert.ok(address_txs['data']); |
||
| 122 | assert.ok(address_txs['total']); |
||
| 123 | |||
| 124 | var expected = require('./test_data/addressTxs.3EU8LRmo5PgcSwnkn6Msbqc8BKNoQ7Xief'); |
||
| 125 | var expectedTxMap = {}; |
||
| 126 | expected.data.forEach(function(tx) { |
||
| 127 | cleanTx(tx); |
||
| 128 | expectedTxMap[tx.hash] = tx; |
||
| 129 | }); |
||
| 130 | |||
| 131 | address_txs.data.forEach(function(tx) { |
||
| 132 | cleanTx(tx); |
||
| 133 | assert.deepEqual(tx, expectedTxMap[tx.hash]); |
||
| 134 | }); |
||
| 135 | |||
| 136 | cb(); |
||
| 137 | }); |
||
| 138 | }); |
||
| 139 | it('test addressUnconfirmedTransactions', function(cb) { |
||
| 140 | client.addressUnconfirmedTransactions("1dice8EMZmqKvrGE4Qc9bUFf9PX3xaYDp", {limit: 23}, function(err, address_txs) { |
||
| 141 | assert.ifError(err); |
||
| 142 | assert.ok('data' in address_txs); |
||
| 143 | assert.ok('total' in address_txs); |
||
| 144 | assert.ok(address_txs['total'] >= address_txs['data'].length); |
||
| 145 | |||
| 146 | cb(); |
||
| 147 | }); |
||
| 148 | }); |
||
| 149 | it('test addressUnspentOutputs', function(cb) { |
||
| 150 | client.addressUnspentOutputs("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", {limit: 23}, function(err, address_utxo) { |
||
| 151 | assert.ifError(err); |
||
| 152 | assert.ok('data' in address_utxo); |
||
| 153 | assert.ok('total' in address_utxo); |
||
| 154 | assert.ok(address_utxo['total'] >= address_utxo['data'].length); |
||
| 155 | |||
| 156 | cb(); |
||
| 157 | }); |
||
| 158 | }); |
||
| 159 | it('test batchAddressUnspentOutputs', function(cb) { |
||
| 160 | this.skip(); |
||
| 161 | |||
| 162 | client.batchAddressUnspentOutputs(["16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "16fVUD4yCuabS153FJGtmLL8tgydsrf6vu"], {limit: 23}, function(err, address_utxo) { |
||
| 163 | assert.ifError(err); |
||
| 164 | assert.ok('data' in address_utxo); |
||
| 165 | assert.ok('total' in address_utxo); |
||
| 166 | assert.ok(address_utxo['total'] >= address_utxo['data'].length); |
||
| 167 | cb(); |
||
| 168 | }); |
||
| 169 | }); |
||
| 170 | it('test verifyAddress', function(cb) { |
||
| 171 | this.skip(); // @TODO: client side |
||
| 172 | |||
| 173 | client.verifyAddress("16dwJmR4mX5RguGrocMfN9Q9FR2kZcLw2z", "HPMOHRgPSMKdXrU6AqQs/i9S7alOakkHsJiqLGmInt05Cxj6b/WhS7kJxbIQxKmDW08YKzoFnbVZIoTI2qofEzk=", function(err, result) { |
||
| 174 | assert.ifError(err); |
||
| 175 | assert.ok(result); |
||
| 176 | |||
| 177 | cb(); |
||
| 178 | }); |
||
| 179 | }); |
||
| 180 | it('test block by hash', function(cb) { |
||
| 181 | client.block("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", function(err, block) { |
||
| 182 | assert.ifError(err); |
||
| 183 | assert.ok(block['hash']); |
||
| 184 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
| 185 | |||
| 186 | var expected = require('./test_data/block.000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
| 187 | |||
| 188 | cleanBlock(block); |
||
| 189 | cleanBlock(expected); |
||
| 190 | |||
| 191 | assert.deepEqual(block, expected); |
||
| 192 | |||
| 193 | cb(); |
||
| 194 | }); |
||
| 195 | }); |
||
| 196 | it('test block by height', function(cb) { |
||
| 197 | client.block(200000, function(err, block) { |
||
| 198 | assert.ifError(err); |
||
| 199 | assert.ok(block['hash']); |
||
| 200 | assert.equal(block['hash'], '000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf'); |
||
| 201 | |||
| 202 | cb(); |
||
| 203 | }); |
||
| 204 | }); |
||
| 205 | it('test blockTransactions', function(cb) { |
||
| 206 | client.blockTransactions("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf", {limit: 23}, function(err, block_txs) { |
||
| 207 | assert.ifError(err); |
||
| 208 | assert.ok(block_txs['data']); |
||
| 209 | assert.ok(block_txs['total']); |
||
| 210 | assert.ok(block_txs['data'].length === 23); |
||
| 211 | |||
| 212 | cb(); |
||
| 213 | }); |
||
| 214 | }); |
||
| 215 | it('test allBlocks', function(cb) { |
||
| 216 | this.skip(); // @TODO |
||
| 217 | |||
| 218 | client.allBlocks({page: 2, limit: 23, sort_dir: 'asc'}, function(err, blocks) { |
||
| 219 | assert.ifError(err); |
||
| 220 | assert.ok(blocks['data']); |
||
| 221 | assert.ok(blocks['total']); |
||
| 222 | assert.ok(blocks['data'].length === 23); |
||
| 223 | assert.equal(blocks['data'][0]['hash'], '000000000cd339982e556dfffa9de94744a4135c53eeef15b7bcc9bdeb9c2182'); |
||
| 224 | assert.equal(blocks['data'][1]['hash'], '00000000fc051fbbce89a487e811a5d4319d209785ea4f4b27fc83770d1e415f'); |
||
| 225 | |||
| 226 | cb(); |
||
| 227 | }); |
||
| 228 | }); |
||
| 229 | it('test blockLatest', function(cb) { |
||
| 230 | client.blockLatest(function(err, block) { |
||
| 231 | assert.ifError(err); |
||
| 232 | assert.ok(block['hash']); |
||
| 233 | |||
| 234 | cb(); |
||
| 235 | }); |
||
| 236 | }); |
||
| 237 | it('test coinbase transaction', function(cb) { |
||
| 238 | client.transaction("0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", function(err, tx) { |
||
| 239 | assert.ifError(err); |
||
| 240 | assert.equal(tx['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); |
||
| 241 | assert.equal(tx['enough_fee'], null); |
||
| 242 | |||
| 243 | cb(); |
||
| 244 | }); |
||
| 245 | }); |
||
| 246 | it('test tx 95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615', function(cb) { |
||
| 247 | client.transaction("95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615", function(err, tx) { |
||
| 248 | assert.ifError(err); |
||
| 249 | assert.equal(tx['hash'], "95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615"); |
||
| 250 | |||
| 251 | var expected = require('./test_data/tx.95740451ac22f63c42c0d1b17392a0bf02983176d6de8dd05d6f06944d93e615'); |
||
| 252 | cleanTx(expected); |
||
| 253 | cleanTx(tx); |
||
| 254 | |||
| 255 | assert.deepEqual(tx, expected); |
||
| 256 | |||
| 257 | cb(); |
||
| 258 | }); |
||
| 259 | }); |
||
| 260 | it('test batch transactions', function(cb) { |
||
| 261 | client.transactions([ |
||
| 262 | "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1", |
||
| 263 | "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098", |
||
| 264 | "4bbe6feeb50e47e2de5ef6a9d7378363823611dd07d4a5ea1799da9ae6a21665", |
||
| 265 | "6c0d3156621051a86b8af3f23dfe211e8a17a01bffe3c2b24cbee65139873c6a", |
||
| 266 | "356210d6b8143e23d0cf4d0dae0ac686015a13fe3b2b46b1cc43a71a36c73355", |
||
| 267 | "a40d1eee0cec3d963d8df2870bd642bd3fd07163e864aeb90fa5efe9ea91c998", |
||
| 268 | "1c7e3c9823baa9bb70b09ed666e8a6b3120b07f84429ed41f05d5504bd58f188", |
||
| 269 | "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80", |
||
| 270 | "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" // not found |
||
| 271 | ], function(err, txs) { |
||
| 272 | assert.ifError(err); |
||
| 273 | |||
| 274 | assert.equal(Object.keys(txs['data']).length, 8); |
||
| 275 | |||
| 276 | var tx1 = txs['data']["c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"]; |
||
| 277 | assert.equal(tx1['hash'], "c791b82ed9af681b73eadb7a05b67294c1c3003e52d01e03775bfb79d4ac58d1"); |
||
| 278 | assert.ok(tx1['confirmations']); |
||
| 279 | |||
| 280 | var tx2 = txs['data']["0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"]; |
||
| 281 | assert.equal(tx2['hash'], "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098"); |
||
| 282 | |||
| 283 | var tx8 = txs['data']["1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"]; |
||
| 284 | assert.equal(tx8['hash'], "1f0a168f0fceb6e48208b23ffb1ad528acfc11c30ab302d447743f2a0fc5fe80"); |
||
| 285 | |||
| 286 | assert.ok(!txs['data']['ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff']); |
||
| 287 | |||
| 288 | cb(); |
||
| 289 | }); |
||
| 290 | }); |
||
| 291 | }); |
||
| 292 | |||
| 570 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.